<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>repassword</title>
    <link rel="stylesheet" href="./css/public.css">
    <style>
        body{
            background: #F0F3F4;
        }
        .container{
            position: absolute;
            width: 300px;
            height: 300px;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            margin: auto;
        }
        .container input{
            width: 100%;
            height: 30px;
            text-indent: .7em;
            margin-top: 20px;
            font-size: 14px;
            border-radius: 3px;
            border: 1px solid #bbb;
        }
        form{
            position: relative;
        }
        form div{
            position: absolute;
            right: 5px;
            cursor: pointer;
        }
        form #eye1{
            top: 30px;
        }
        form #eye2{
            top: 80px;
        }
        form [type=submit]{
            border: 1px solid #c0e6f1;
            line-height: 2em;
            font-size: 16px;
            color: #fff;
            background: #23B7E5;
        }
        #cancel{
            border: 1px solid #c0e6f1;
            line-height: 2em;
            font-size: 16px;
            color: #23B7E5;
            background: #fff;
        }
    </style>
</head>
<body>
    <div class="container animation">
        <form action="javascript:" role="form">
            <input type="password" id="password1" required placeholder="新密码" value="lin20010223=">
            <div class="i" id="eye1">&#xe61a;</div>
            <input type="password" id="password2" required placeholder="确认密码" value="lin20010223=">
            <div class="i" id="eye2">&#xe61a;</div>
            <input type="submit" id="submit" value="确定">
            <input type="button" value="取消" id="cancel">
        </form>
    </div>
    <script src="node_modules/axios/dist/axios.js"></script>
    <script>
        axios.get('https://ty.php800.cn/api/token.php',{
            headers:{
                TOKEN:localStorage.getItem('token'),
                SAT:'1234567'
            }
        }).then((res)=>{
            console.log(res)
            if(!res.data.verify){
                top.window.location.href='./login.html'
            }
        })
    </script>
    <script>
        $('#cancel').onclick=function(){
            location.href='./overview_table.html'
        }
        function hide_show(eye,password){
            let chane_eye=document.querySelector(eye),
                input=document.querySelector(password)
                chane_eye.onclick=function(){
                if(input.type=="text"){
                    input.type="password";
                    this.innerHTML="&#xe61a;"
                }else{
                    input.type="text";
                    this.innerHTML="&#xe71c;"
                }
            }
        }
        function $(selector){
            return document.querySelector(selector)
        }
        hide_show('#eye1','#password1')
        hide_show('#eye2','#password2')
        $('#submit').onclick=function(){
            console.log($('#password1').value,$('#password2').value,localStorage.getItem('thisPeopleId'))
            if($('#password1'.value)){
                console.log('新密码不能为空')
                return;
            }
            if($('#password1'.value)){
                console.log('确认密码不能为空')
                return;
            }
            let formdata=new FormData()
            formdata.append('id',localStorage.getItem('thisPeopleId'))
            formdata.append('password',$('#password1').value)
            formdata.append('password2',$('#password2').value)
            axios.post('https://ty.php800.cn/api/member/userPassword.php',formdata,{
                headers:{
                    TOKEN:localStorage.getItem('token'),
                    SAT:'1234567'
                }
            }).then((res)=>{
                console.log(res.data.verify)
                if(res.data.verify){
                    alert('修改成功')
                location.href='./overview_table.html'
                }else{
                    alert('密码修改失败')
                }
            })
        }
    </script>
</body>
</html>